﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Convertor.Interface;

namespace Convertor
{
    /// <summary>
    /// TestPlugin.xaml 的交互逻辑
    /// </summary>
    public partial class TestPlugin : Window
    {

        private SelectedPluginContent plugin;

        private IOutputContent output;

        private ConvertDelegate convertFun;
        public TestPlugin()
        {
            InitializeComponent();
        }

        public TestPlugin(SelectedPluginContent plugin, IOutputContent output, ConvertDelegate convertFun)
            : this()
        {
            this.output = output;
            this.plugin = plugin;
            this.convertFun = convertFun;
        }

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            tbInput.Text = output.LastOriginal.ToString();
            startTest();

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            startTest();
        }

        private void startTest()
        {
            output = new OutputContent(tbInput.Text, tbInput.Text);
            Thread th = new Thread(new ThreadStart(() =>
            {
                IOutputContent content = convertFun(output, plugin);
                tbOutput.Dispatcher.Invoke(() => { tbOutput.Text = content.Output.ToString(); });
            }));
            th.IsBackground = true;
            th.Start();
        }
    }
}
